﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XYX.Http.Host
{
    /// <summary>
    /// 容器创建者
    /// </summary>
    public class ContainerBuilder
    {
        /// <summary>
        /// 容器
        /// </summary>
        private Dictionary<Type, Resolver> dicContainer = new Dictionary<Type, Resolver>();
        /// <summary>
        /// 对象实例
        /// </summary>
        private Type HandlerInstanceType;
        /// <summary>
        /// 注册
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public ContainerBuilder Register<T>() where T : class, new()
        {
           
            HandlerInstanceType = typeof(T);
            Resolver resolver = new Resolver()
            {
                InstanceType = HandlerInstanceType
            };
            if (!dicContainer.ContainsKey(HandlerInstanceType))
            {
                dicContainer[HandlerInstanceType] = resolver;
            }
            return this;

        }
        /// <summary>
        /// 构建
        /// </summary>
        /// <returns></returns>
        public IContainer Builder()
        {
            Container container = new Container(dicContainer);
            return container;
        }
    }
}
